home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_init.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  71.2 KB  |  2,210 lines

  1. % Copyright (C) 1989-2009 Artifex Software, Inc. All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_init.ps 9334 2009-01-08 09:17:18Z ghostgum $
  14. % Initialization file for the interpreter.
  15. % When this is run, systemdict is still writable.
  16.  
  17. % Comment lines of the form
  18. %    %% Replace <n> <file(s)>
  19. % indicate places where the next <n> lines should be replaced by
  20. % the contents of <file(s)>, when creating a single merged init file.
  21.  
  22. % The interpreter can call out to PostScript code.  All procedures
  23. % called in this way, and no other procedures defined in these
  24. % initialization files, have names that begin with %, e.g.,
  25. % (%Type1BuildChar) cvn.
  26.  
  27. % Interpreter library version number
  28. % NOTE: the interpreter code requires that the first non-comment token
  29. % in this file be an integer, and that it match the compiled-in version!
  30. 864
  31.  
  32. % Check the interpreter revision.
  33. dup revision ne
  34.  { (gs: Interpreter revision \() print revision 10 string cvs print
  35.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  36.    (\).\n) print flush //null 1 .quit
  37.  }
  38. if pop
  39.  
  40. % Acquire userdict, and set its length if necessary.
  41. /userdict where
  42.  { pop userdict maxlength 0 eq }
  43.  { true }
  44. ifelse
  45. systemdict exch
  46.  {        % userdict wasn't already set up by iinit.c.
  47.    dup /userdict
  48.    currentdict dup 200 .setmaxlength        % userdict
  49.    .forceput            % userdict is local, systemdict is global
  50.  }
  51. if begin
  52.  
  53. % Define dummy local/global operators if needed.
  54. systemdict /.setglobal known
  55.  { true .setglobal
  56.  }
  57.  { /.setglobal { pop } bind def
  58.    /.currentglobal { false } bind def
  59.    /.gcheck { pop false } bind def
  60.  }
  61. ifelse
  62.  
  63. % Define .languagelevel if needed.
  64. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  65.  
  66. % Optionally choose a default paper size other than U.S. letter.
  67. % The default page size for many devices is set at compile time to 
  68. % letter, but this can be changed to A4 although this is rarely done.  
  69. % Some devices such as bbox have a different default page size,
  70. % and should not be set to A4 or letter.
  71. % When ghostscript is used in countries that use the international
  72. % standard page size A4 rather than US letter, the page size of 
  73. % devices that default to letter or A4 can be changed by setting
  74. % DEFAULTPAPERSIZE.
  75. % /DEFAULTPAPERSIZE (a4) def
  76.  
  77. % Turn on array packing for the rest of initialization.
  78. true setpacking
  79.  
  80. % Define the old MS-DOS EOF character as a no-op.
  81. % This is a hack to get around the absurd habit of MS-DOS editors
  82. % of adding an EOF character at the end of the file.
  83. <1a> cvn { } def
  84.  
  85. % Acquire the debugging flags.
  86. currentdict /DEBUG known   /DEBUG exch def
  87.  
  88. % if DEBUG is set, set ALL of the subset debugging flags
  89. mark    % '[' isn't defined yet
  90.   /CCFONTDEBUG        % Compiled Fonts
  91.   /CFFDEBUG        % CFF Fonts
  92.   /CMAPDEBUG        % CMAP 
  93.   /DOCIEDEBUG        % CIE color
  94.   /EPSDEBUG        % EPS handling
  95.   /FAPIDEBUG        % Font API
  96.   /INITDEBUG        % Initialization
  97.   /PDFDEBUG        % PDF Interpreter
  98.   /PDFOPTDEBUG        % PDF Optimizer (Linearizer)
  99.   /PDFWRDEBUG        % PDF Writer
  100.   /SETPDDEBUG        % setpagedevice
  101.   /TTFDEBUG        % TTF Fonts
  102.   /VGIFDEBUG        % ViewGIF
  103.   /VJPGDEBUG        % ViewJPEG
  104.   /RESMPDEBUG        % Resource map
  105. counttomark array astore exch pop % ']' isn't defined yet
  106. { dup currentdict exch known DEBUG or def } forall
  107.  
  108. currentdict /PDFSTEP known /PDFSTEP exch def
  109. % if PDFSTEP is on, turn on PDFDEBUG
  110. PDFSTEP { /PDFDEBUG true def } if
  111.  
  112.   /VMDEBUG
  113.     INITDEBUG {{print mark
  114.             systemdict /level2dict known
  115.          { .currentglobal dup false .setglobal vmstatus
  116.            true .setglobal vmstatus 3 -1 roll pop
  117.            6 -2 roll pop .setglobal
  118.          }
  119.          { vmstatus 3 -1 roll pop
  120.          }
  121.         ifelse usertime 16#fffff and counttomark
  122.           { ( ) print (           ) cvs print }
  123.         repeat pop
  124.         ( ) print systemdict length (    ) cvs print
  125.         ( ) print countdictstack (  ) cvs print
  126.         ( <) print count (    ) cvs print (>\n) print flush
  127.       }}
  128.       {{pop
  129.       }}
  130.      ifelse
  131.   def
  132.  
  133. currentdict /BATCH known   /BATCH exch def
  134. currentdict /DELAYBIND known   /DELAYBIND exch def
  135. currentdict /DISKFONTS known   /DISKFONTS exch def
  136. currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
  137. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  138. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  139. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  140. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  141. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  142. currentdict /JOBSERVER known   /JOBSERVER exch def
  143. currentdict /NOBIND known   /NOBIND exch def
  144. /.bind /bind load def
  145. NOBIND { /bind { } def } if
  146. currentdict /NOCACHE known   /NOCACHE exch def
  147. currentdict /NOCCFONTS known   /NOCCFONTS exch def
  148. currentdict /NOCIE known   /NOCIE exch def
  149. currentdict /NOPSICC known   /NOPSICC exch def
  150. currentdict /NODISPLAY known   not /DISPLAYING exch def
  151. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  152. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  153. currentdict /NOGC known   /NOGC exch def
  154. currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
  155. currentdict /NOMEDIAATTRS known /NOMEDIAATTRS exch def
  156. currentdict /NOOUTERSAVE known   /NOOUTERSAVE exch def
  157. currentdict /NOPAGEPROMPT known   /NOPAGEPROMPT exch def
  158. currentdict /NOPAUSE known   /NOPAUSE exch def
  159. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  160. currentdict /NOPROMPT known   /NOPROMPT exch def
  161. currentdict /NOTRANSPARENCY known   /NOTRANSPARENCY exch def
  162. currentdict /DOPS known   /DOPS exch def
  163. currentdict /NOSUBSTDEVICECOLORS known   /NOSUBSTDEVICECOLORS exch def
  164. % The default value of ORIENT1 is true, not false.
  165. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  166. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  167. currentdict /OUTPUTFILE known    % obsolete
  168.  { /OutputFile /OUTPUTFILE load def
  169.    currentdict /OUTPUTFILE .undef
  170.  } if
  171. currentdict /QUIET known   /QUIET exch def
  172. % DELAYSAFER is effectively the same as newer NOSAFER
  173. currentdict /DELAYSAFER known { /DELAYSAFER true def /NOSAFER true def } if
  174. /SAFER currentdict /NOSAFER known {
  175.   false
  176. } {
  177.   currentdict /SAFER known
  178.   currentdict /PARANOIDSAFER known or    % PARANOIDSAFER is equivalent
  179. }
  180. ifelse def
  181. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  182. currentdict /STRICT known   /STRICT exch def
  183. currentdict /TTYPAUSE known   /TTYPAUSE exch def
  184. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  185. currentdict /RENDERTTNOTDEF known /RENDERTTNOTDEF exch def
  186.  
  187. % Acquire environment variables.
  188. currentdict /DEVICE known not
  189.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  190.  
  191. (START) VMDEBUG
  192.  
  193. % Open the standard files, so they will be open at the outermost save level.
  194. (%stdin) (r) file pop
  195. (%stdout) (w) file pop
  196. (%stderr) (w) file pop
  197.  
  198. /.currentuserparams where {
  199.   pop mark
  200.     % The Adobe implementations appear to have very large maximum
  201.     % stack sizes.  This turns out to actually make a difference,
  202.     % since some badly-behaved files include extremely long procedures,
  203.     % or construct huge arrays on the operand stack.
  204.     % We reset the stack sizes now so that we don't have to worry
  205.     % about overflowing the (rather small) built-in stack sizes
  206.     % during initialization.
  207.   /MaxDictStack 500
  208.   /MaxExecStack 5000
  209.   /MaxOpStack 65414
  210.   .dicttomark .setuserparams
  211. } if
  212.  
  213. % Define a procedure for skipping over an unneeded section of code.
  214. % This avoids allocating space for the skipped procedures.
  215. % We can't use readline, because that imposes a line length limit.
  216. /.skipeof    % <string> .skipeof -
  217.  { currentfile exch 1 exch .subfiledecode flushfile
  218.  } .bind def
  219.  
  220. % Define procedures to assist users who don't read the documentation.
  221. userdict begin
  222. /help
  223.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  224.    print flush
  225.  } .bind def
  226. end
  227.  
  228. % Define =string, which is used by some PostScript programs even though
  229. % it isn't documented anywhere.
  230. % Put it in userdict so that each context can have its own copy.
  231. userdict /=string 256 string put
  232.  
  233. % Print the greeting.
  234.  
  235. /printgreeting
  236.  { mark
  237.    product (Ghostscript) search
  238.     { pop pop pop
  239.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  240.     }
  241.     { pop
  242.     }
  243.    ifelse
  244.    (\n) copyright
  245.    (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  246.    revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  247.    revisiondate 10000 idiv ( \()
  248.    revision 10 mod
  249.    revision 100 mod 10 idiv (.)
  250.    revision 100 idiv ( )
  251.    product
  252.    counttomark
  253.     { (%stdout) (w) file exch 0 .writecvp
  254.     } repeat pop
  255.  } .bind def
  256.  
  257. QUIET not { printgreeting flush } if
  258.  
  259. % Define a special version of def for making operator procedures.
  260. /obind {    % <name> <proc> obind <name> <oper>
  261.   1 index exch .makeoperator
  262. } .bind def
  263. /odef {        % <name> <proc> odef -
  264.   1 index exch .makeoperator def
  265. } .bind def
  266.  
  267. % Define a special version of def for storing local objects into global
  268. % dictionaries.  Like .forceput, this exists only during initialization.
  269. /.forcedef {        % <key> <value> .forcedef -
  270.   1 .argindex pop    % check # of args
  271.   currentdict 3 1 roll .forceput
  272. } .bind odef
  273.  
  274. % Define procedures for accessing variables in systemdict and userdict
  275. % regardless of the contents of the dictionary stack.
  276. /.systemvar {        % <name> .systemvar <value>
  277.   //systemdict exch get
  278. } .bind odef
  279. /.userdict {        % - .userdict <dict>
  280.   /userdict .systemvar
  281. } .bind odef
  282. /.uservar {        % <name> .uservar <value>
  283.   .userdict exch get
  284. } .bind odef
  285.  
  286. % If we're delaying binding, remember everything that needs to be bound later.
  287. DELAYBIND NOBIND not and
  288.  { .currentglobal false .setglobal
  289.    systemdict /.delaybind 2000 array .forceput
  290.    .setglobal
  291.    userdict /.delaycount 0 put
  292.     % When we've done the delayed bind, we want to stop saving.
  293.     % Detect this by the disappearance of .delaybind.
  294.    /bind
  295.     { /.delaybind .systemvar dup length 0 ne
  296.        { .delaycount 2 index put
  297.          .userdict /.delaycount .delaycount 1 add put
  298.        }
  299.        { pop /.bind cvx exec
  300.        }
  301.       ifelse
  302.     } .bind def
  303.  } if
  304.  
  305. %**************** BACKWARD COMPATIBILITY ****************
  306. /hwsizedict mark /HWSize //null .dicttomark readonly def
  307. /copyscanlines {        % <device> <y> <string> copyscanlines <substr>
  308.   0 3 1 roll 3 index //hwsizedict .getdeviceparams
  309.   exch pop exch pop aload pop 3 2 roll
  310.   0 exch //null exch .getbitsrect exch pop
  311. } bind odef
  312. currentdict /hwsizedict .undef
  313. /getdeviceprops
  314.  { //null .getdeviceparams
  315.  } bind odef
  316. /.putdeviceprops
  317.  { //null true counttomark 1 add 3 roll .putdeviceparams
  318.    dup type /booleantype ne
  319.     { dup mark eq { /unknown /rangecheck } if
  320.       counttomark 4 add 1 roll cleartomark pop pop pop
  321.       /.putdeviceprops .systemvar exch signalerror
  322.     }
  323.    if
  324.  } bind odef
  325. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  326. /.setfilladjust { dup .setfilladjust2 } bind odef
  327. /.writecvs { 0 .writecvp } bind odef
  328. %**************** DEPRECATED PROCEDURES ****************
  329. %**************** DO NOT USE THESE IN NEW CODE ****************
  330. /max { .max } bind def        % use .max instead
  331. /min { .min } bind def        % use .min instead
  332. /unread /.unread load def    % use .peekstring instead
  333. %**************** END OF BACKWARD COMPATIBILITY SECTION ****************
  334.  
  335. % Utility for removing all entries from a dictionary
  336. /.PurgeDict   % <dict> .PurgeDict -
  337. { { true
  338.     1 index { pop exch pop false exit
  339.     } forall
  340.     { exit
  341.     } if
  342.     1 index exch undef
  343.   } loop
  344.   pop
  345. } bind def
  346.  
  347. % Define predefined procedures substituting for operators,
  348. % in alphabetical order.
  349.  
  350. userdict /#copies 1 put
  351. % Adobe implementations don't accept /[ or /], so we don't either.
  352. ([) cvn
  353.     /mark load def
  354. (]) cvn
  355.     {counttomark array astore exch pop} odef
  356. % .beginpage is redefined if setpagedevice is present.
  357. /.beginpage { } odef
  358. % In LanguageLevel 3, copypage erases the page.
  359. /copypage {
  360.     .languagelevel 3 ge
  361.     dup { 0 } { 1 } ifelse .endpage .doneshowpage {
  362.       .currentnumcopies 1 index .outputpage
  363.       (>>copypage, press <return> to continue<<\n) .confirm
  364.       dup { erasepage } if
  365.     } if pop
  366.     systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
  367.     .beginpage
  368. } odef
  369. /currentmatrix {
  370.     dup type /arraytype ne
  371.     { /currentmatrix load  /typecheck signalerror } if
  372.     dup length 6 ne
  373.     { /currentmatrix load  /rangecheck signalerror } if
  374.     .currentmatrix 6 .argindex astore pop
  375. } odef
  376. % .currentnumcopies is redefined in Level 2.
  377. /.currentnumcopies { #copies } odef
  378. /setcolorscreen where { pop        % not in all Level 1 configurations
  379.    /currentcolorscreen
  380.     { .currenthalftone
  381.        { { 60.0 exch 0.0 exch 3 copy 6 copy }    % halftone - not possible
  382.          { 3 copy 6 copy }            % screen
  383.          { }                % colorscreen
  384.        }
  385.       exch get exec
  386.     } odef
  387. } if
  388. /currentscreen
  389.     { .currenthalftone
  390.        { { 60.0 exch 0.0 exch }            % halftone - not possible
  391.          { }                % screen
  392.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  393.        }
  394.       exch get exec
  395.     } odef
  396. /.echo /echo load def
  397. userdict /.echo.mode true put
  398. /echo    {dup /.echo.mode exch store .echo} odef
  399. /.eexec_param_dict mark
  400.   /eexec true
  401.   /seed 55665
  402. .dicttomark readonly def
  403. /eexec {
  404.     % Rebind .currentresourcefile if it is the source for the eexec.
  405.   dup //.eexec_param_dict //filterdict /eexecDecode get exec
  406.   cvx exch .currentresourcefile eq
  407.   //systemdict begin { {exec} .execasresource } { exec } ifelse
  408.     % Only pop systemdict if it is still the top element,
  409.     % because this is apparently what Adobe interpreters do.
  410.   currentdict //systemdict eq { end } if
  411. } odef
  412. % .endpage is redefined if setpagedevice is present.
  413. /.endpage { 2 ne } odef
  414. % erasepage mustn't use gsave/grestore, because we call it before
  415. % the graphics state stack has been fully initialized.
  416. /erasepage
  417.     { /currentcolor where
  418.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  419.        { /currentcmykcolor where
  420.           { pop currentcmykcolor { setcmykcolor } }
  421.           { currentrgbcolor { setrgbcolor } }
  422.          ifelse
  423.        }
  424.       ifelse
  425.           currentoverprint false setoverprint 1 setgray .fillpage setoverprint
  426.           exec
  427.     } odef
  428. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  429. /executive
  430.     { { prompt
  431.          { (%statementedit) (r) .systemvmfile } stopped
  432.          { pop pop $error /errorname get /undefinedfilename eq
  433.         { .clearerror exit } if        % EOF
  434.            /handleerror .systemvar exec //null        % ioerror??
  435.          }
  436.         if
  437.         cvx { .runexec } execute
  438.       } loop
  439.     } bind def
  440. /filter
  441.     { //filterdict 1 .argindex .knownget
  442.        { exch pop exec }
  443.        { /filter .systemvar /undefined signalerror }
  444.       ifelse
  445.     } odef
  446. % handleerror procedure as mentioned in the "Operators" section of the PLRM Section 8.2
  447. % This invokes the handleerror procedure from errordict (unless we are running under a
  448. % JOBSERVER where we want to always use a defined error handler (many error handlers in
  449. % 'wild' PostScript files are broken and don't indicate the error in any useful fashion).
  450. %
  451. % We run the handleerror procedure using .internalstopped so that broken error handlers
  452. % won't cause nested errors (Unexpected Error conditions).
  453. /handleerror
  454.     JOBSERVER {
  455.       { /.GShandleerror .systemvar .internalstopped pop } bind % always use .GShandleerror.
  456.     } {
  457.       { /errordict .systemvar /handleerror get .internalstopped pop } bind % PLRM standard errorhandling
  458.     } ifelse def
  459. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  460. /identmatrix {
  461.     dup type /arraytype ne { /identmatrix load  /typecheck signalerror } if
  462.     dup length 6 ne { /identmatrix load  /rangecheck signalerror } if
  463.     dup 0 //identmatrix putinterval
  464. } odef
  465. /languagelevel 1 def        % gs_lev2.ps may change this
  466. /makeimagedevice { false makewordimagedevice } odef
  467. /matrix    { 6 array identmatrix } odef
  468. % .promptmsg is redefined if the interpreter includes readline support.
  469. /.promptmsg {
  470.     (GS) print
  471.     count 0 ne { (<) print count =only } if
  472.     (>) print flush
  473. } bind def
  474. /prompt    { flush flushpage NOPROMPT not { .promptmsg } if } bind def
  475. /pstack    { 0 1 count 3 sub { index == } for } bind def
  476. /putdeviceprops
  477.     { .putdeviceprops { erasepage } if } odef
  478. /quit    { /quit load 0 .quit } odef
  479. /run    { dup type /filetype ne { (r) .systemvmfile } if
  480.         % We must close the file when execution terminates,
  481.         % regardless of the state of the stack,
  482.         % and then propagate an error, if any.
  483.       cvx null {.runexec} .errorexec
  484.     } odef
  485. % Execute a file.
  486. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  487. % we detect that here, since we need to handle this even if we start out
  488. % without job control in effect.
  489. %
  490. % What we push on the e-stack is the following to be executed in this order:
  491. %    <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  492. /.runexec1 {        % <file|fileproc> .runexec1 -
  493.   dup type /filetype ne { cvx exec } if
  494.   cvx //null 2 .stopped
  495.     % If we got back here from a startjob, just keep going.
  496.     % startjob replaces the null on the o-stack with a procedure
  497.     % to be executed when we get back here.
  498.   dup //null ne { exec true } { pop false } ifelse
  499. } bind def
  500. /.runexec2 {        % <continue> <file|fileproc> .runexec2 -
  501.   exch {
  502.     .runexec
  503.   } {
  504.     dup type /filetype ne { cvx exec } if
  505.     closefile
  506.   } ifelse
  507. } bind def
  508. /.runexec {        % <file|fileproc> .runexec -
  509.   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  510. } bind def
  511. % The following is only for compatibility with Adobe interpreters.
  512. /setdash {
  513.     0 .argindex type dup /integertype eq exch /realtype eq or not {
  514.       /setdash .systemvar /typecheck signalerror
  515.     } if
  516.     1 .argindex length 11 gt { /setdash .systemvar /limitcheck signalerror } if
  517.     //setdash
  518. } odef
  519. /setdevice
  520.   {
  521.     .setdevice
  522.       {
  523.         mark
  524.           {         % Reset the halftone since the device may differ
  525.             currenthalftone
  526.             dup type /dicttype eq
  527.               { sethalftone }
  528.               { pop }
  529.             ifelse
  530.           }
  531.         stopped
  532.         cleartomark
  533.         erasepage
  534.       }
  535.     if
  536.   }
  537. odef
  538. /setlinecap {
  539.     dup 2 gt { /setlinecap .systemvar /rangecheck signalerror } if
  540.     .setlinecap
  541. } odef
  542. /setlinejoin {
  543.     dup 2 gt { /setlinejoin .systemvar /rangecheck signalerror } if
  544.     .setlinejoin
  545. } odef
  546. /setmatrix {
  547.     dup type /arraytype ne {
  548.       dup type /packedarraytype ne {
  549.         /setmatrix load  /typecheck signalerror
  550.       } if
  551.     } if
  552.     dup length 6 ne { /setmatrix load  /rangecheck signalerror } if
  553.     dup aload pop .setmatrix pop
  554. } odef
  555. /showpage {
  556.     0 .endpage .doneshowpage {
  557.       .currentnumcopies true .outputpage
  558.       (>>showpage, press <return> to continue<<\n) .confirm
  559.       initgraphics
  560.           currentoverprint false setoverprint 1 setcolor
  561.           .fillpage
  562.           setoverprint 0 setcolor
  563.     }
  564.     { initgraphics } ifelse
  565.     systemdict /..page_default_spaces .knownget { //.PurgeDict exec } if
  566.     .beginpage
  567. } odef
  568. % Code output by Adobe Illustrator relies on the fact that
  569. % `stack' is a procedure, not an operator!!!
  570. /stack    { 0 1 count 3 sub { index = } for } bind def
  571. /start    { BATCH { //null 0 .quit } { executive } ifelse } def
  572. % Internal uses of stopped that aren't going to do a stop if an error occurs
  573. % should use .internalstopped to avoid setting newerror et al.
  574. /.internalstopped { //null 1 .stopped //null ne } bind def
  575. /store {    % Don't alter operands before completing.
  576.     1 .argindex where { 2 index 2 index put pop pop } { def } ifelse
  577. } odef
  578. /.typenames mark .typenames counttomark packedarray exch pop def
  579. /type {
  580.     //.typenames .type
  581. } odef
  582. currentdict /.typenames .undef
  583. % When running in Level 1 mode, this interpreter is supposed to be
  584. % compatible with PostScript "version" 54.0 (I think).
  585. /version (54.0) readonly def
  586. /.wheredict 10 dict def
  587. /.where /where load def
  588. /where {
  589.     //.wheredict 1 .argindex .knownget { exec } { .where } ifelse
  590. } odef
  591.  
  592. % internaldict is defined in systemdict, but the dictionary is allocated
  593. % in local VM.  However, the procedure must be global, since it is an
  594. % "operator" and must be bind-able into global procedures.
  595. % We make a procedure for creating it, since we must create a new one
  596. % for each context with private local VM.
  597. /.makeinternaldict {
  598.   .currentglobal true .setglobal
  599.     [ /dup .systemvar 1183615869 /eq .systemvar
  600.     [ /pop .systemvar //null ] cvx
  601.     false .setglobal
  602.     dup 1 10 dict .forceput    % proc is global, dict is local
  603.     true .setglobal
  604.     [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  605.       /ifelse .systemvar
  606.     ] cvx executeonly
  607.   exch .setglobal
  608. } odef
  609. systemdict /internaldict dup .makeinternaldict .makeoperator
  610. .forceput        % proc is local, systemdict is global
  611.  
  612. % Define some additional built-in procedures (beyond the ones defined by
  613. % the PostScript Language Reference Manual).
  614. % Warning: these are not guaranteed to stay the same from one release
  615. % to the next!
  616. /concatstrings    %    (str1) (str2) concatstrings (str1str2)
  617.     { exch dup length 2 index length add string    % str2 str1 new
  618.       dup dup 4 2 roll copy        % str2 new new new1
  619.       length 4 -1 roll putinterval
  620.     } bind def
  621. /copyarray
  622.     { dup length array copy } bind def
  623. % Copy a dictionary per the Level 2 spec even in Level 1.
  624. /.copydict        % <fromdict> <todict> .copydict <todict>
  625.     { dup 3 -1 roll { put dup } forall pop } bind def
  626. /copystring
  627.     { dup length string copy } bind def
  628. /findlibfile {
  629.   .systemvmlibfile { dup .filename pop exch true } { false } ifelse
  630. } odef
  631. /.growdictlength    % get size for growing a dictionary
  632.     { length 3 mul 2 idiv 1 add
  633.     } bind def
  634. /.growdict        % grow a dictionary
  635.     { dup .growdictlength .setmaxlength
  636.     } bind def
  637. /.growput        % put, grow the dictionary if needed
  638.     { 2 index length 3 index maxlength eq
  639.        { 3 copy pop known not { 2 index .growdict } if
  640.        } if
  641.       put
  642.     } bind def
  643. % .localvmarray may be an operator: see zsysvm.c.
  644. /.localvmarray where {
  645.   pop
  646. } {
  647.   /.localvmarray {
  648.     .currentglobal false .setglobal
  649.     exch array exch .setglobal
  650.   } bind def
  651. } ifelse
  652. /.localvmdict where {
  653.   pop
  654. } {
  655.   /.localvmdict {
  656.     .currentglobal false .setglobal
  657.     exch dict exch .setglobal
  658.   } bind def
  659. } ifelse
  660. /.packtomark
  661.     { counttomark packedarray exch pop } bind def
  662. /ppstack
  663.     { 0 1 count 3 sub { index === } for } bind def
  664. /runlibfile
  665.     {        % We don't want to bind 'run' into this procedure,
  666.              % since run may get redefined.
  667.       findlibfile
  668.        { exch pop /run .systemvar exec }
  669.        { /undefinedfilename signalerror }
  670.       ifelse
  671.     } bind def
  672. /selectdevice
  673.     { finddevice setdevice .setdefaultscreen } bind def
  674. /signalerror        % <object> <errorname> signalerror -
  675.     { /errordict .systemvar exch get exec } bind def
  676. /signaloperror {    % <object> <errorname> signaloperror -
  677.     % Same as signalerror, except that if we are inside a pseudo-operator
  678.     % or .errorexec, we use its error object, just as errors generated by
  679.     % real operators do.
  680.     /errordict .systemvar exch get
  681.     .finderrorobject { 3 -1 roll pop exch } if
  682.     exec
  683. } bind def
  684.  
  685. % Define the =[only] procedures.  Also define =print,
  686. % which is used by some PostScript programs even though
  687. % it isn't documented anywhere.
  688. /write=only {
  689.     .writecvs
  690. } bind def
  691. /write= {
  692.     1 index exch write=only (\n) writestring
  693. } bind def
  694. /=only    { (%stdout) (w) file exch write=only } bind def
  695. /=    { =only (\n) print } bind def
  696. /=print    /=only load def
  697. % Temporarily define == as = for the sake of runlibfile0.
  698. /== /= load def
  699.  
  700. % The following procedures are documented.
  701. /copydevice {        % <device> copydevice <newdevice>
  702.   false .copydevice2
  703. } odef
  704. /finddevice {        % <devicename> finddevice <device>
  705.   /devicedict .systemvar exch get
  706.   dup 1 get //null eq {
  707.         % This is the first request for this type of device.
  708.         % Create a default instance now.
  709.         % Stack: [proto null]
  710.     .currentglobal true .setglobal exch
  711.     dup dup 0 get copydevice 1 exch put
  712.     exch .setglobal
  713.   } if 1 get
  714. } bind def
  715. /findprotodevice {    % <devicename> findprotodevice <protodevice>
  716.   /devicedict .systemvar exch get 0 get
  717. } bind def
  718.  
  719. % Run a resource file.  This allows us to distinguish resource objects
  720. % from objects coming from input files.
  721. userdict /.currentresourcefile //null put
  722. /.execasresource {    % <file> <proc|runfile> .execasresource -
  723.   /stopped .systemvar
  724.   /.currentresourcefile .uservar
  725.         % Stack: file proc -stopped- currfile
  726.   .userdict /.currentresourcefile 5 index cvlit put
  727.   2 .execn        % stopped <file>
  728.   .userdict /.currentresourcefile 3 -1 roll put
  729.   { stop } if
  730. } bind def
  731. /.runresource {        % <file> .runresource -
  732.   { /run .systemvar exec } .execasresource
  733. } bind def
  734.  
  735. % Define procedures for getting and setting the current device resolution.
  736.  
  737. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  738.  { 2 copy mark exch //null .dicttomark .getdeviceparams
  739.    dup mark eq        % if true, not found
  740.     { pop dup /undefined signalerror }
  741.     { 5 1 roll pop pop pop pop }
  742.    ifelse
  743.  } bind def
  744. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  745.  { currentdevice /HWResolution gsgetdeviceprop
  746.  } bind def
  747. /gssetresolution    % <[xres yres]> gssetresolution -
  748.  { 2 array astore mark exch /HWResolution exch
  749.    currentdevice copydevice putdeviceprops setdevice
  750.  } bind def
  751.  
  752. % Define auxiliary procedures needed for the above.
  753. /shellarguments        % -> shell_arguments true (or) false
  754.     { /ARGUMENTS where
  755.        { /ARGUMENTS get dup type /arraytype eq
  756.           { aload pop /ARGUMENTS //null store true }
  757.           { pop false }
  758.          ifelse }
  759.        { false } ifelse
  760.     } bind def
  761. /.confirm {
  762.   DISPLAYING NOPAUSE not TTYPAUSE or and {
  763.     % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  764.     % and wait for the user to type something.
  765.     % If the user just types a newline, flush it.
  766.     NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
  767.     .confirmread
  768.   } {
  769.     pop
  770.   } ifelse
  771. } bind def
  772. /.confirmread {
  773.   TTYPAUSE {
  774.     (/dev/tty) (r) file dup read pop pop closefile
  775.   } {
  776.     .echo.mode false echo
  777.     (%stdin) (r) file dup read {
  778.       dup (\n) 0 get eq { pop pop } { unread } ifelse
  779.     } {
  780.       pop
  781.     } ifelse echo
  782.   } ifelse
  783. } bind def
  784.  
  785. % Define the procedure used by .runfile, .runstdin and .runstring
  786. % for executing user input.
  787. % This is called with a procedure or executable file on the operand stack.
  788. /.execute {        % <obj> .execute <stopped>
  789.   stopped $error /newerror get and
  790.    { /handleerror .systemvar exec flush true } { false } ifelse
  791. } bind def
  792. /execute {        % <obj> execute -
  793.   .execute pop
  794. } odef
  795. % Define an execute analogue of runlibfile0.
  796. /execute0 {        % <obj> execute0 -
  797.   .execute { /execute0 cvx 1 .quit } if
  798. } bind def
  799. % Define the procedure that the C code uses for running files
  800. % named on the command line.
  801. /.runfile {
  802.   { runlibfile } execute0
  803. } def
  804. % Define the procedure that the C code uses for running piped input.
  805. % We don't use the obvious { (%stdin) run }, because we want the file to be
  806. % reopened if a startjob does a restore.
  807. /.runstdin {
  808.   { { (%stdin) (r) file cvx } .runexec } execute0
  809. } bind def
  810. % Define the procedure that the C code uses for running commands
  811. % given on the command line with -c.  We turn the string into a file so that
  812. % .runexec can do the right thing with a startjob.
  813. /.runstring {
  814.   0 0 .systemvmstring .systemvmSFD cvx { .runexec } execute0
  815. } bind def
  816. % Define the procedure that the C code uses to set up for executing
  817. % a string that may be received in pieces.
  818. /.runstringbegin {
  819.   1 .systemvmarray dup 0 /.needinput load put cvx    % { .needinput } in systemvm
  820.   0 0 .systemvmstring .systemvmSFD cvx .runexec
  821. } bind def
  822.  
  823. % Define a special version of runlibfile that aborts on errors.
  824. /runlibfile0
  825.     { cvlit dup dup /.currentfilename exch def
  826.        { findlibfile not { stop } if }
  827.       stopped
  828.        { (Can't find \(or open\) initialization file ) print
  829.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  830.        } if
  831.       exch pop cvx 
  832.       { stopped } 0 get 3 -1 roll 2 array astore cvx exec
  833.       /.currentfilename exch store
  834.        { (While reading ) print .currentfilename print (:\n) print flush
  835.          /handleerror .systemvar exec /runlibfile0 1 .quit
  836.        } if
  837.     } bind def
  838. % Temporarily substitute it for the real runlibfile.
  839. /.runlibfile /runlibfile load def
  840. /runlibfile /runlibfile0 load def
  841.  
  842. % Create the error handling machinery.
  843. % Define the standard error handlers.
  844. % The interpreter has created the ErrorNames array.
  845. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  846.  {    % This is the handler that gets used for recursive errors,
  847.     % or errors outside the scope of a 'stopped'.
  848.    2 copy SHORTERRORS
  849.     { (%%[ Error: ) print =only flush
  850.       (; OffendingCommand: ) print =only ( ]%%) =
  851.     }
  852.     { (Unrecoverable error: ) print =only flush
  853.       ( in ) print = flush
  854.       count 2 gt
  855.        { (Operand stack:\n  ) print
  856.          count 1 sub -1 2 { (  ) print index =only flush } for
  857.      () = flush
  858.        } if
  859.     }
  860.    ifelse
  861.    -1 0 1 //ErrorNames length 1 sub
  862.     { dup //ErrorNames exch get 3 index eq
  863.        { not exch pop exit } { pop } ifelse
  864.     }
  865.    for exch pop .quit
  866.  } bind def
  867. /.errorhandler        % <command> <errorname> .errorhandler -
  868.   {        % Detect an internal 'stopped'.
  869.     1 .instopped { //null eq { pop pop stop } if } if
  870.     (I) false .setdebug
  871.     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  872.      { .unstoppederrorhandler
  873.      } if    % detect error recursion
  874.     $error /globalmode .currentglobal false .setglobal put
  875.     $error /.inerror true put
  876.     $error /newerror true put
  877.     $error exch /errorname exch put
  878.     $error exch /command exch put
  879.     $error /errorinfo known not { $error /errorinfo //null put } if
  880.     $error /recordstacks get $error /errorname get /VMerror ne and
  881.      {        % Attempt to store the stack contents atomically.
  882.        count array astore dup $error /ostack 4 -1 roll
  883.        % Grab the execstack, then remove to two elements that are from
  884.        % this error handler (not interesting).
  885.        countexecstack array execstack dup length 2 sub 0 exch getinterval
  886.        $error /estack 3 -1 roll
  887.        countdictstack array dictstack $error /dstack 3 -1 roll
  888.        put put put aload pop
  889.      }
  890.      { $error /dstack .undef
  891.        $error /estack .undef
  892.        $error /ostack .undef
  893.      }
  894.     ifelse
  895.     $error /position currentfile status
  896.      { currentfile { fileposition } .internalstopped { pop //null } if
  897.      }
  898.      {        % If this was a scanner error, the file is no longer current,
  899.         % but the command holds the file, which may still be open.
  900.        $error /command get dup type /filetype eq
  901.         { { fileposition } .internalstopped { pop //null } if }
  902.         { pop //null }
  903.        ifelse
  904.      }
  905.     ifelse put
  906.         % During initialization, we don't reset the allocation
  907.         % mode on errors.
  908.     $error /globalmode get $error /.nosetlocal get and .setglobal
  909.     $error /.inerror false put
  910.     stop
  911.   } bind def
  912. % Define the standard handleerror.  We break out the printing procedure
  913. % (.printerror) so that it can be extended for binary output
  914. % if the Level 2 facilities are present.
  915.   /.printerror
  916.    { $error begin newerror
  917.      {
  918.        /command load errorname SHORTERRORS
  919.     { (%%[ Error: ) print =only flush
  920.       (; OffendingCommand: ) print =only
  921.       errorinfo dup //null eq {
  922.         pop
  923.       } {
  924.         (;\nErrorInfo:) print
  925.         dup type /arraytype eq
  926.           { { ( ) print =only } forall }
  927.           { ( ) print =only }
  928.         ifelse
  929.       } ifelse
  930.           ( ]%%) = flush
  931.     }
  932.     { (Error: ) print ==only flush
  933.       ( in ) print ==only flush
  934.       errorinfo dup //null eq {
  935.         pop
  936.       } {
  937.         (\nAdditional information: ) print ==only flush
  938.       } ifelse
  939.       .printerror_long
  940.     }
  941.        ifelse
  942.        .clearerror flush
  943.      }
  944.      { % newerror is false, test to see if user has set handleerror to a different
  945.        % routine, if so execute it, otherwise, just return.  This code deals with the
  946.        % Genoa issue of setting /handleerror, and then calling it, without an error
  947.        % being set.  We were erroring in this case, due to /command load failing.
  948.  
  949.         //JOBSERVER {
  950.         /errordict .systemvar /handleerror get /.GShandleerror .systemvar ne
  951.     } {
  952.         false
  953.     } ifelse
  954.          { /errordict .systemvar begin /handleerror load .internalstopped pop end
  955.          }
  956.          if
  957.      }
  958.      ifelse    % newerror 
  959.      end
  960.      flush
  961.     } bind def     
  962.   /.printerror_long            % long error printout,
  963.                     % $error is on the dict stack
  964.    {    % Push the (anonymous) stack printing procedure.
  965.     %  <heading> <==flag> <override-name> <stackname> proc
  966.        {
  967.      currentdict exch .knownget    % stackname defined in $error?
  968.      {
  969.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  970.        /errordict .systemvar exch .knownget    % overridename defined?
  971.        { 
  972.          exch pop exch pop exec    % call override with <stack>
  973.        }
  974.        { 
  975.          exch print exch        % print heading. stack <==flag> <stack>
  976.          1 index not { () = } if
  977.          { 1 index { (\n    ) } { (   ) } ifelse print
  978.            dup type /dicttype eq
  979.            {
  980.          (--dict:) print
  981.          dup rcheck {
  982.            dup length =only (/) print dup maxlength =only
  983.            dup wcheck not { ((ro)) print } if
  984.          } if
  985.          /gcheck where {
  986.            pop gcheck { ((G)) } { ((L)) } ifelse print
  987.          } {
  988.            pop
  989.          } ifelse (--) print
  990.            }
  991.            {
  992.          dup type /stringtype eq 2 index or
  993.          { ==only } { =only } ifelse
  994.            } ifelse
  995.          } forall
  996.          pop
  997.        }
  998.        ifelse            % overridden
  999.      }
  1000.      { pop pop pop
  1001.      }
  1002.      ifelse                % stack known
  1003.        }
  1004.  
  1005.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  1006.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  1007.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  1008.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  1009.        () =
  1010.        pop    % printing procedure
  1011.  
  1012.        errorname /VMerror eq
  1013.     { (VM status:) print mark vmstatus
  1014.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  1015.       cleartomark () =
  1016.     } if
  1017.  
  1018.        .languagelevel 2 ge
  1019.     { (Current allocation mode is ) print
  1020.       globalmode { (global\n) } { (local\n) } ifelse print
  1021.     } if
  1022.  
  1023.        .oserrno dup 0 ne
  1024.     { (Last OS error: ) print
  1025.       errorname /VMerror ne
  1026.        { dup .oserrorstring { = pop } { = } ifelse }
  1027.        { = }
  1028.       ifelse
  1029.     }
  1030.     { pop
  1031.     }
  1032.        ifelse
  1033.  
  1034.        position //null ne
  1035.     { (Current file position is ) print position = }
  1036.        if
  1037.  
  1038.    } bind def
  1039. % Define a procedure for clearing the error indication.
  1040. /.clearerror
  1041.  { $error /newerror false put
  1042.    $error /errorname //null put
  1043.    $error /errorinfo //null put
  1044.    0 .setoserrno
  1045.  } bind def
  1046.  
  1047. % Define $error.  This must be in local VM.
  1048. .currentglobal false .setglobal
  1049. /$error 40 dict .forcedef    % $error is local, systemdict is global
  1050.         % newerror, errorname, command, errorinfo,
  1051.         % ostack, estack, dstack, recordstacks,
  1052.         % binary, globalmode,
  1053.         % .inerror, .nosetlocal, position,
  1054.         % plus extra space for badly designed error handers.
  1055. $error begin
  1056.   /newerror false def
  1057.   /recordstacks true def
  1058.   /binary false def
  1059.   /globalmode .currentglobal def
  1060.   /.inerror false def
  1061.   /.nosetlocal true def
  1062.   /position //null def
  1063.   /errorinfo //null def
  1064. end
  1065. % Define errordict similarly.  It has one entry per error name,
  1066. %   plus handleerror.  However, some astonishingly badly written PostScript
  1067. %   files require it to have at least one empty slot.
  1068. /errordict ErrorNames length 3 add dict
  1069. .forcedef        % errordict is local, systemdict is global
  1070. .setglobal        % back to global VM
  1071. % For greater Adobe compatibility, we put all non-standard errors in a
  1072. %   separate dictionary, gserrordict.  It does not need to be in local VM,
  1073. %   because PostScript programs do not access it.
  1074. %   NOTE: the name gserrordict is known to the interpreter.
  1075. /gserrordict 5 dict def
  1076. % Register an error in errordict.  We make this a procedure because we only
  1077. % register the Level 1 errors here: the rest are registered by "feature"
  1078. % files.  However, ErrorNames contains all of the error names regardless of
  1079. % what features are included, so we have to "know" that VMerror is the last
  1080. % Level 1 error.
  1081. /.registererror        % <name> .registererror -
  1082.  { errordict exch .registererror2
  1083.  } bind def
  1084. /.registererror2    % <dict> <name> .registererror -
  1085.  { .currentglobal true .setglobal    % create procs in global VM
  1086.    3 1 roll
  1087.    mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx put
  1088.    .setglobal
  1089.  } bind def
  1090. ErrorNames
  1091.  { dup .registererror /VMerror eq {exit} if
  1092.  } forall
  1093. errordict begin
  1094. % The handlers for interrupt and timeout are special; there is no
  1095. % 'current object', so they push their own name.
  1096.    { /interrupt /timeout }
  1097.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  1098.    } forall
  1099. /handleerror    % this key is 'well known' and some PS may redefine it
  1100.  { /.printerror .systemvar exec
  1101.  } bind def
  1102. end        % errordict
  1103.  
  1104. % Put non-standard errors in gserrordict.
  1105. gserrordict /unknownerror errordict /unknownerror get put
  1106. errordict /unknownerror .undef
  1107. % Define a stable private copy of handleerror that we will always use under
  1108. % JOBSERVER mode.
  1109. /.GShandleerror errordict /handleerror get def
  1110.  
  1111. % Define the [write]==[only] procedures.
  1112. /.dict 8 dict dup
  1113. begin def
  1114.   /.cvp {1 index exch 1 .writecvp} bind def
  1115.   /.p {1 index exch writestring} bind def
  1116.   /.p1 {2 index exch writestring} bind def
  1117.   /.p2 {3 index exch writestring} bind def
  1118.   /.print
  1119.     { dup type .dict exch .knownget { exec } { .cvp } ifelse
  1120.     } bind def
  1121.   /arraytype
  1122.     {dup rcheck
  1123.       {() exch dup xcheck
  1124.         {({) .p2
  1125.          {exch .p1
  1126.           1 index exch .print pop ( )} forall
  1127.          (})}
  1128.         {([) .p2
  1129.          {exch .p1
  1130.           1 index exch .print pop ( )} forall
  1131.          (])}
  1132.        ifelse exch pop .p}
  1133.       {.cvp}
  1134.      ifelse} bind def
  1135.   /packedarraytype /arraytype load def
  1136. {//.dict begin .print pop end}
  1137.   bind
  1138. end
  1139.  
  1140. /write==only exch def
  1141. /write== {1 index exch write==only (\n) writestring} bind def
  1142. /==only { (%stdout) (w) file exch write==only } bind def
  1143. /== {==only (\n) print} bind def
  1144.  
  1145. % Define [write]===[only], an extension that prints dictionaries
  1146. % in readable form and doesn't truncate strings.
  1147. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  1148. begin def
  1149.   /dicttype
  1150.     { dup rcheck
  1151.        { (<< ) .p1
  1152.           { 2 index 3 -1 roll .print pop ( ) .p1
  1153.         1 index exch .print pop ( ) .p
  1154.           }
  1155.          forall (>>) .p
  1156.        }
  1157.        { .cvp
  1158.        }
  1159.       ifelse
  1160.     } bind def
  1161.   /stringtype
  1162.     { 1 index exch 2 .writecvp
  1163.     } bind def
  1164.  
  1165. {//.dict begin .print pop end}
  1166.   bind
  1167. end
  1168.  
  1169. /write===only exch def
  1170. /write=== {1 index exch write===only (\n) writestring} bind def
  1171. /===only { (%stdout) (w) file exch write===only } bind def
  1172. /=== { ===only (\n) print } bind def
  1173.  
  1174. % Create the initialization queue.
  1175.  
  1176. /.delayed_init_queue 10 dict def
  1177.  
  1178. /.schedule_init   %   <priority> <proc> .schedule_init -
  1179. {
  1180.   //.delayed_init_queue 2 index known {
  1181.     (.delayed_init_queue priority conflict with ) print 1 index =
  1182.     /.schedule_init cvx /configurationerror signalerror
  1183.   } if
  1184.   //.delayed_init_queue 3 1 roll .growput
  1185. } bind def
  1186.  
  1187. /.execute_scheduled_inits %   - .execute_scheduled_inits -
  1188. {
  1189.   { 0 //null //.delayed_init_queue {     % maxp {} p {}
  1190.       3 index 2 index lt {
  1191.         4 2 roll
  1192.       } if
  1193.       pop pop
  1194.     } forall
  1195.     exch //.delayed_init_queue exch undef
  1196.     dup //null eq {
  1197.       pop exit
  1198.     } if
  1199.     exec
  1200.   } loop
  1201. } bind def
  1202.  
  1203. (END PROCS) VMDEBUG
  1204.  
  1205. % Define the font directory.
  1206. /FontDirectory false .setglobal 100 dict true .setglobal
  1207. .forcedef        % FontDirectory is local, systemdict is global
  1208.  
  1209. % Define the encoding dictionary.
  1210. /EncodingDirectory 16 dict def    % enough for Level 2 + PDF standard encodings
  1211.  
  1212. % Define .findencoding.  (This is redefined in Level 2.)
  1213. /.findencoding
  1214.  { //EncodingDirectory exch get exec
  1215.  } bind def
  1216. /.defineencoding
  1217.  { //EncodingDirectory 3 1 roll put
  1218.  } bind def
  1219. % If we've got the composite font extensions, define findencoding.
  1220. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  1221. /rootfont where { pop /findencoding { .findencoding } def } if
  1222.  
  1223. % Define .registerencoding.
  1224. % NOTE: This procedure no longer does anything, but it must continue to
  1225. % exist for the sake of toolbin/encs2c.ps.
  1226. /.registerencoding {    % <index> <array> .registerencoding -
  1227.   pop pop
  1228. } bind odef
  1229.  
  1230. % Load StandardEncoding.
  1231. %% Replace 1 (gs_std_e.ps)
  1232. (gs_std_e.ps) dup runlibfile VMDEBUG
  1233.  
  1234. % Load ISOLatin1Encoding.
  1235. %% Replace 1 (gs_il1_e.ps)
  1236. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1237.  
  1238. % Define stubs for the Symbol and Dingbats encodings.
  1239. % Note that the first element of the procedure must be the file name,
  1240. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1241.  
  1242.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1243. %% Replace 3 (gs_sym_e.ps)
  1244.   EncodingDirectory /SymbolEncoding
  1245.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1246.   bind put
  1247.  
  1248.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1249. %% Replace 3 (gs_dbt_e.ps)
  1250.   EncodingDirectory /DingbatsEncoding
  1251.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1252.   bind put
  1253.  
  1254. (END FONTDIR/ENCS) VMDEBUG
  1255.  
  1256. % Construct a dictionary of all available devices.
  1257. % These are (read-only) device prototypes that can't be
  1258. % installed or have their parameters changed.  For this reason,
  1259. % the value in the dictionary is actually a 2-element writable array,
  1260. % to allow us to create a default instance of the prototype on demand.
  1261.  
  1262.     % Loop until the .getdevice gets a rangecheck.
  1263. errordict /rangecheck 2 copy get
  1264. errordict /rangecheck { pop stop } put    % pop the command
  1265.   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  1266.   1 add dict  /devicedict 1 index def
  1267.   begin            % 2nd copy of count is on stack
  1268.    { dup .devicename exch
  1269.      dup wcheck { dup } { //null } ifelse 2 array astore def
  1270.    } repeat
  1271.   end
  1272. put        % errordict /rangecheck
  1273. .clearerror
  1274. /devicenames devicedict { pop } forall devicedict length packedarray def
  1275.  
  1276. % Determine the default device.
  1277. /defaultdevice DISPLAYING
  1278.  { systemdict /DEVICE .knownget
  1279.     { devicedict 1 index known not
  1280.        { (Unknown device: ) print =
  1281.      flush /defaultdevice cvx 1 .quit
  1282.        }
  1283.       if
  1284.     }
  1285.     { .getdefaultdevice .devicename
  1286.     }
  1287.    ifelse
  1288.  }
  1289.  { /nullpage
  1290.  }
  1291. ifelse
  1292. /.defaultdevicename 1 index def
  1293. finddevice    % make a copy
  1294. def
  1295. devicedict /Default devicedict .defaultdevicename get put
  1296.  
  1297. (END DEVS) VMDEBUG
  1298.  
  1299. % Define statusdict, for the benefit of programs
  1300. % that think they are running on a LaserWriter or similar printer.
  1301. %% Replace 1 (gs_statd.ps)
  1302. (gs_statd.ps) runlibfile
  1303.  
  1304. (END STATD) VMDEBUG
  1305.  
  1306. % Load the standard font environment.
  1307. %% Replace 1 (gs_fonts.ps)
  1308. (gs_fonts.ps) runlibfile
  1309.  
  1310. (END GS_FONTS) VMDEBUG
  1311.  
  1312. % Define the default halftone screen and BG/UCR functions now, so that
  1313. % it will bind in the original definitions of set[color]screen.
  1314. % We make this a procedure so we can call it again when switching devices.
  1315.  
  1316. % Use an ordered dither for low-resolution devices.
  1317. /.setloreshalftone {    % <dpi> .setloreshalftone -
  1318.     % The following 'ordered dither' spot function was contributed by
  1319.     % Gregg Townsend.  Thanks, Gregg!
  1320.    16.001 div 0            % not 16: avoids rounding problems
  1321.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1322.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1323.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1324.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1325.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1326.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1327.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1328.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1329.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1330.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1331.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1332.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1333.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1334.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1335.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1336.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1337.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1338.      > exch get 256 div
  1339.     }
  1340.    bind
  1341.         % Use correct, per-plane screens for CMYK devices only.
  1342.    //systemdict /setcolorscreen known processcolors 4 eq and
  1343.     { 3 copy 6 copy //setcolorscreen }
  1344.     { //setscreen }
  1345.    ifelse
  1346. } bind def
  1347. /.setloresscreen {    % <dpi> .setloresscreen -
  1348.   .setloreshalftone
  1349.   0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1350.   /setstrokeadjust where { pop true setstrokeadjust } if
  1351. } bind def
  1352. % Use a 45-degree spot screen for high-resolution devices.
  1353. % The PS3 CET insists that the screen be an array and not a packedarray (!).
  1354. currentpacking false setpacking
  1355. /.linescreen
  1356. % The following screen algorithm is used by permission of the author.
  1357.     { ((C) 1989 Berthold K.P. Horn) pop
  1358.       1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1359.       1 0.08 sub mul add 2 div
  1360.     }
  1361. bind readonly def
  1362. setpacking
  1363. /.sethireshalftone {    % <dpi> .sethireshalftone <doscreen>
  1364.     % According to information published by Hewlett-Packard,
  1365.     % they use a 60 line screen on 300 DPI printers and
  1366.     % an 85 line screen on 600 DPI printers.
  1367.     % However, we use a 106 line screen, which produces smoother-
  1368.     % looking shades but fewer of them (32 vs. 50).
  1369.     % 46 was suggested as a good frequency value for printers
  1370.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1371.     % Imagesetters need even higher frequency screens.
  1372.    //systemdict /DITHERPPI known
  1373.     { DITHERPPI
  1374.     }
  1375.     { dup cvi 100 idiv 15 .min
  1376.        {//null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1377.       exch get
  1378.      }
  1379.    ifelse
  1380.    1 index 4.01 div .min    % at least a 4x4 cell
  1381.    45
  1382.    //.linescreen
  1383.     % Determine whether we have lots of process colors.
  1384.     % If so, don't bother with color screening or gamma correction.
  1385.     % Also don't do gamma correction on very high-resolution devices.
  1386.     % (This should depend on dot gain, not resolution, but we don't
  1387.     % currently have a way to determine this.) Ignore missing components
  1388.         % (*Values = 1).
  1389.    currentdevice mark
  1390.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1391.    .dicttomark .getdeviceparams
  1392.    counttomark 2 idiv 1 sub
  1393.     { exch pop dup 1 le
  1394.        { pop }
  1395.        { exch dup 1 le
  1396.           { pop }
  1397.           { .min }
  1398.         ifelse
  1399.        }
  1400.       ifelse
  1401.     }
  1402.    repeat
  1403.    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1404.     % Stack: doscreen dpi freq angle proc
  1405.     % Ghostscript currently doesn't use correct, per-plane halftones
  1406.     % unless setcolorscreen has been executed.  Since these are
  1407.     % computationally much more expensive than binary halftones,
  1408.     % we check to make sure they are really warranted, i.e., we have
  1409.     % a high-resolution CMYK device (i.e., not a display) with
  1410.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1411.    4 -1 roll 150 ge
  1412.     { /setcolorscreen where
  1413.        { pop //systemdict /COLORSCREEN known
  1414.       { COLORSCREEN }
  1415.       { 3 index }
  1416.      ifelse
  1417.      dup false ne
  1418.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1419.     % For really high-quality screening on printers, we need to
  1420.     % give each plane its own screen angle.  Unfortunately,
  1421.     % this currently has very large space and time costs.
  1422.         true eq        % true => different angles,
  1423.                 % 0 => same angles
  1424.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1425.          }
  1426.         if //setcolorscreen
  1427.       }
  1428.       { pop //setscreen    % false => single binary screen
  1429.       }
  1430.      ifelse
  1431.        }
  1432.        { //setscreen        % setcolorscreen not known
  1433.        }
  1434.       ifelse
  1435.     }
  1436.     { //setscreen            % not high resolution
  1437.     }
  1438.    ifelse
  1439. } bind def
  1440. /.sethiresscreen {    % <dpi> .sethiresscreen 
  1441.   .sethireshalftone     % pushes true if a screen halftone used
  1442.             % Stack: doscree
  1443.   {
  1444.     % Set the transfer function to lighten up the grays.
  1445.     % Parameter values closer to 1 are better for devices with
  1446.     % less dot spreading; lower values are better with more spreading.
  1447.     % The value 0.8 is a compromise that will probably please no one!
  1448.     %
  1449.     % Because of a bug in FrameMaker, we have to accept operands
  1450.     % outside the valid range of [0..1].
  1451.     {
  1452.       dup dup 0.0 gt exch 1.0 lt and
  1453.       {
  1454.         0.8 exp
  1455.       }
  1456.       if
  1457.     }
  1458.   }
  1459.   {
  1460.      % Set the transfer function to the identity.
  1461.      0 array cvx     % Genoa CET won't accept a packed array!
  1462.   }
  1463.   ifelse
  1464.   settransfer
  1465.   /setstrokeadjust where
  1466.   { pop false setstrokeadjust }
  1467.   if
  1468.  
  1469.   % Increase fill adjustment so that we effectively use Adobe's
  1470.   % any-part-of-pixel rule.
  1471.   0.5 .setfilladjust
  1472. } bind def
  1473. % Set the default screen and BG/UCR.
  1474. /.setdefaultbgucr {
  1475.   systemdict /setblackgeneration known {
  1476.     { pop 0 } dup setblackgeneration setundercolorremoval
  1477.   } if
  1478. } bind def
  1479. /.useloresscreen {    % - .useloresscreen <bool>
  1480.     % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1481.   72 72 matrix defaultmatrix dtransform abs exch abs .min
  1482.   dup 150 lt //systemdict /DITHERPPI known not and
  1483. } bind def
  1484.  
  1485. % The following implementation uses LL2 extensions, but only in stopped
  1486. % contexts so that with LL1, the .set??reshalftone will be used.
  1487. %
  1488. %    - .getdefaulthalftone <halftonedict> true    if default found
  1489. %                  false            
  1490. /.getdefaulthalftone {
  1491.   % try the device to see if it has a default halftone
  1492.   { currentdevice /HalftoneDefault gsgetdeviceprop } .internalstopped
  1493.   { pop pop false }        % no device property
  1494.   { dup type /dicttype eq { true } { pop false } ifelse }
  1495.   ifelse
  1496.   % stack: <halftonedict> true    if default found
  1497.   %         false          not found
  1498.   dup not
  1499.   { % device did not provide a default, try Resource
  1500.     pop { /Default /Halftone /findresource .systemvar exec } .internalstopped 
  1501.     { pop pop false } { true } ifelse
  1502.   }
  1503.   if
  1504. } bind def
  1505.  
  1506. /.setdefaulthalftone {
  1507.   .getdefaulthalftone 
  1508.   { sethalftone }
  1509.   { % default not found
  1510.     .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
  1511.   }
  1512.   ifelse
  1513. } bind def
  1514.  
  1515. /.setdefaultscreen {
  1516.   .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
  1517.   .setdefaultbgucr
  1518. } bind def
  1519.  
  1520. % Rendering intent mapping for setcolorrendering1 and PDF interpreter
  1521. /.renderingintentdict mark
  1522.   /Perceptual 0
  1523.   /RelativeColorimetric 1
  1524.   /Saturation 2
  1525.   /AbsoluteColorimetric 3
  1526. .dicttomark readonly def
  1527.  
  1528. % Load basic color support
  1529. %% Replace 1 (gs_cspace.ps)
  1530. (gs_cspace.ps) runlibfile
  1531.  
  1532. (END BASIC COLOR) VMDEBUG
  1533.  
  1534.  
  1535. % Load image support
  1536. %% Replace 1 (gs_img.ps)
  1537. (gs_img.ps) runlibfile
  1538.  
  1539. (END IMAGE) VMDEBUG
  1540.  
  1541. % Auxiliary procedures for generating file name templates.
  1542.  
  1543. % Convert a path name into a string suitable for filenameforall
  1544. % For example: (a\\b*?c) to (a\\\\b\\*\\?c)
  1545. /.makepathtemplate {    % str1 -- str2
  1546.    dup length dup add string 0    % result string up to twice the size
  1547.    0 1 4 index length 1 sub {
  1548.      3 index exch get
  1549.      dup 92 eq {        % \ -> \\
  1550.         2 index 2 index 92
  1551.         put
  1552.         exch 1 add exch
  1553.      } 
  1554.      if
  1555.      dup 42 eq {        % * -> \*
  1556.         2 index 2 index 92
  1557.         put
  1558.         exch 1 add exch
  1559.      } 
  1560.      if
  1561.      dup 63 eq {        % ? -> \?
  1562.         2 index 2 index 92
  1563.         put
  1564.         exch 1 add exch
  1565.      } 
  1566.      if
  1567.      2 index 2 index 3 -1 roll put 1 add
  1568.    } for
  1569.    0 exch getinterval exch pop
  1570. } bind def
  1571.  
  1572. %   false <dir_list> <template> .generate_dir_list_templates_with_length <t1> ... <tN>
  1573. %   true  <dir_list> <template> .generate_dir_list_templates_with_length <t1> <l1> ... <tN> <ln>
  1574. %
  1575. % Generates various valid templates combining a directory list with a given template.
  1576. % With 'true' operand it also returns lengths of directory pathes.
  1577. %
  1578. % Example1 (DOS, Windows) :
  1579. %       false [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
  1580. %       (/gs/lib/*/*) (/gs/Resource/*/*) (\\gs8.00\\Resource/*/*)
  1581. %
  1582. % Example2 (OpenVMS) :
  1583. %       false [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
  1584. %       ((gs:[lib.*]*) [gs:[Resource.*]*) ([gs800:[Resource.*]*)
  1585. %
  1586. /.generate_dir_list_templates_with_length
  1587. {                                                  % [dl] (templ)
  1588.   % We need to convert paths into templates,
  1589.   % because it can include '\' on DOS.
  1590.   % In same time, the <template> must not convert,
  1591.   % because it is already a template.
  1592.   % Besides that, we cannot combine template using .file_name_combine,
  1593.   % because template syntax breaks the platform path syntax.
  1594.   % To resolve this, we first convert the <template> into 
  1595.   % a fake filename, and combine it with path,
  1596.   % obtaining a correct separator. Then we replace
  1597.   % the fake file name with the given template.
  1598.   %
  1599.  
  1600.   % Create the fake file name :
  1601.   dup dup length string copy                       % b [dl] (templ) (ffn)
  1602.   (*) 0 get (?) 0 get (\\) 0 get (x) 0 get 0 0     % b [dl] (templ) (ffn) * ? \ x i j
  1603.   { 1 index 7 index length ge { exit } if
  1604.     6 index 2 index get                            % b [dl] (templ) (ffn) * ? \ x i j c
  1605.     dup 7 index eq                                 % b [dl] (templ) (ffn) * ? \ x i j c bool
  1606.     1 index 7 index eq or { % *?
  1607.       pop 2 index
  1608.     } if                                           % b [dl] (templ) (ffn) * ? \ x i j C
  1609.     dup 5 index eq {        % \
  1610.       3 2 roll 1 add 3 1 roll                      % b [dl] (templ) (ffn) * ? \ x i' j C
  1611.       2 index 8 index length ge { pop exit } if
  1612.       pop 6 index 2 index get                      % b [dl] (templ) (ffn) * ? \ x i' j C'
  1613.     } if
  1614.     7 index 2 index 3 2 roll put                   % b [dl] (templ) (ffn) * ? \ x i' j
  1615.     1 add exch 1 add exch                          % b [dl] (templ) (ffn) * ? \ x i'' j'
  1616.   } loop                                           % b [dl] (templ) (ffn) * ? \ x i j
  1617.   6 1 roll pop                                     % b [dl] (templ) (ffn) j * ? \ x
  1618.   exch pop exch pop exch pop exch                  % b [dl] (templ) (ffn) x j
  1619.   { dup 3 index length ge { exit } if
  1620.     3 copy exch put
  1621.     1 add
  1622.   } loop
  1623.   pop pop                                          % b [dl] (templ) (ffn)
  1624.  
  1625.   % An internal procedure : 
  1626.   {                                 % {} b [dl] (templ) (ffn) (dffn)
  1627.     dup length 
  1628.     1 sub % drop 'x', which was added above.
  1629.     exch                            % {} b [dl] (templ) (ffn) ldffn (dffn)
  1630.     .makepathtemplate               % {} b [dl] (templ) (ffn) ldffn (Dffn)
  1631.     dup                             % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn)
  1632.     4 index length dup              % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL
  1633.     2 index length                  % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL DffnL
  1634.     exch sub                        % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL i
  1635.     exch getinterval                % {} b [dl] (templ) (ffn) ldffn (Dffn) (suffix)
  1636.     4 index exch copy pop           % {} b [dl] (templ) (ffn) ldffn (dt)
  1637.     5 index {
  1638.       exch                          % {} b [dl] (templ) (ffn) (dt) ldffn
  1639.       7 2 roll                      % (dt) ldffn {} b [dl] (templ) (ffn)
  1640.     } {
  1641.       exch pop                      % {} b [dl] (templ) (ffn) (dt)
  1642.       6 1 roll                      % (dt) {} b [dl] (templ) (ffn)
  1643.     } ifelse
  1644.   }
  1645.   5 1 roll                                         % {} b [dl] (templ) (ffn)
  1646.  
  1647.   % Generate templates :
  1648.   dup .file_name_is_absolute {
  1649.     dup                                            % {} b [dl] (templ) (ffn) (ffn)
  1650.     5 index exec                                   % (t1) {} b [dl] (templ) (ffn)
  1651.   } {
  1652.     2 index {                                      % ... {} b [dl] (templ) (ffn) (d)
  1653.       1 index                                      % ... {} b [dl] (templ) (ffn) (d) (ffn)
  1654.       false .file_name_combine {                   % ... {} b [dl] (templ) (ffn) (dffn)
  1655.         5 index exec                               % ... (t1) ?l1 {} b [dl] (templ) (ffn)
  1656.       } {                                          % ... {} b [dl] (templ) (ffn) (d) (ffn)
  1657.         pop pop                                    % ... {} b [dl] (templ) (ffn)
  1658.       } ifelse
  1659.     } forall
  1660.   } ifelse                                         % (t1) ?l1 (t2) ?l2 ... (tN) ?ln {} b [dl] (templ) (ffn)
  1661.   pop pop pop pop pop                              % (t1) ?l1 (t2) ?l2 ... (tN) ?ln
  1662. } bind def
  1663.  
  1664. %   <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
  1665. %
  1666. % Generates various valid templates combining a directory list with a given template.
  1667. % It's the 'false' case of the function above.
  1668. %
  1669. /.generate_dir_list_templates
  1670. { //false 3 1 roll //.generate_dir_list_templates_with_length exec
  1671. } bind def
  1672.  
  1673. % Load the initialization files for optional features.
  1674. %% Replace 4 INITFILES
  1675. systemdict /INITFILES known
  1676.  { INITFILES { dup runlibfile VMDEBUG } forall
  1677.  }
  1678. if
  1679.  
  1680. % If Level 2 (or higher) functionality is implemented, enable it now.
  1681. /.setlanguagelevel where {
  1682.   pop 2 .setlanguagelevel
  1683.     % If the resource machinery is loaded, fix up some things now.
  1684.   /.fixresources where { pop .fixresources } if
  1685. } if
  1686. /ll3dict where {
  1687.   pop 3 .setlanguagelevel
  1688. } if
  1689.  
  1690. (END INITFILES) VMDEBUG
  1691.  
  1692. % Create a null font.  This is the initial font.
  1693. 8 dict dup begin
  1694.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1695.   /FontType 3 def
  1696.   /FontName () def
  1697.   /Encoding StandardEncoding def
  1698.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1699.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  1700.   /PaintType 0 def        % shouldn't be needed!
  1701. end
  1702. /NullFont exch definefont setfont
  1703.  
  1704. % Define NullFont as the font.
  1705. /NullFont currentfont def
  1706.  
  1707. % Load initial fonts from FONTPATH directories, Fontmap file,
  1708. % and/or .getccfont as appropriate.
  1709. .loadinitialfonts
  1710.  
  1711. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1712. /undefinefont where {
  1713.   pop /NullFont undefinefont
  1714. } {
  1715.   FontDirectory /NullFont .undef
  1716. } ifelse
  1717.  
  1718. (END FONTS) VMDEBUG
  1719.  
  1720. % Restore the real definition of runlibfile.
  1721. /runlibfile /.runlibfile load def
  1722. currentdict /.runlibfile .undef
  1723.  
  1724. % Bind all the operators defined as procedures.
  1725. /.bindoperators        % binds operators in currentdict
  1726.  { % Temporarily disable the typecheck error.
  1727.    errordict /typecheck 2 copy get
  1728.    errordict /typecheck { pop } put    % pop the command
  1729.    currentdict
  1730.     { dup type /operatortype eq
  1731.        { % This might be a real operator, so bind might cause a typecheck,
  1732.      % but we've made the error a no-op temporarily.
  1733.      .bind        % do a real bind even if NOBIND is set
  1734.        }
  1735.       if pop pop
  1736.     } forall
  1737.    put
  1738.  } def
  1739. NOBIND DELAYBIND or not { .bindoperators } if
  1740.  
  1741. % Establish a default environment.
  1742.  
  1743. defaultdevice
  1744. % The following line used to skip setting of page size and resolution if
  1745. % NODISPLAY was selected.  We think this was only to save time and memory,
  1746. % and it is a bad idea because it prevents setting the resolution in this
  1747. % situation, which pstoedit (among other programs) relies on.
  1748. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1749.  
  1750. % If the paper size is not specifed and the device defaults to 
  1751. % letter or A4 paper, select the DEFAULTPAPERSIZE.
  1752. systemdict /DEFAULTPAPERSIZE known not 
  1753.  {
  1754.    % Use .defaultpapersize if it returns a known paper size
  1755.    .defaultpapersize 
  1756.     { 
  1757.       false statusdict /.pagetypenames get 
  1758.        {
  1759.     2 index eq { pop true exit } if
  1760.        }
  1761.       forall
  1762.        {systemdict exch /DEFAULTPAPERSIZE exch put}
  1763.        {QUIET
  1764.      { pop } 
  1765.      { (Unknown .defaultpapersize: ) print ==only (.) = }
  1766.     ifelse
  1767.        } 
  1768.       ifelse
  1769.     } 
  1770.    if
  1771.  } 
  1772. if
  1773. systemdict /DEFAULTPAPERSIZE known
  1774. systemdict /PAPERSIZE known not and
  1775. systemdict /DEVICEWIDTH known not and
  1776. systemdict /DEVICEHEIGHT known not and
  1777. systemdict /DEVICEWIDTHPOINTS known not and
  1778. systemdict /DEVICEHEIGHTPOINTS known not and
  1779.  {
  1780.    defaultdevice mark /PageSize //null .dicttomark .getdeviceparams 
  1781.    .dicttomark /PageSize get
  1782.    dup 0 get 0.5 add cvi 612 eq 1 index 1 get 0.5 add cvi 792 eq and
  1783.    1 index 0 get 0.5 add cvi 595 eq 2 index 1 get 0.5 add cvi 842 eq and
  1784.    or exch pop
  1785.    {
  1786.      % the default paper size was letter, so replace it with DEFAULTPAPERSIZE
  1787.      /PAPERSIZE DEFAULTPAPERSIZE def
  1788.    } if
  1789.  }
  1790. if
  1791.  
  1792. systemdict /DEVICEWIDTH known
  1793. systemdict /DEVICEHEIGHT known or
  1794. systemdict /DEVICEWIDTHPOINTS known or
  1795. systemdict /DEVICEHEIGHTPOINTS known or
  1796. systemdict /DEVICEXRESOLUTION known or
  1797. systemdict /DEVICEYRESOLUTION known or
  1798. systemdict /PAPERSIZE known or
  1799. not { (%END DEVICE) .skipeof } if
  1800. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1801. systemdict /PAPERSIZE known
  1802. systemdict /DEVICEWIDTH known not and
  1803. systemdict /DEVICEHEIGHT known not and
  1804. systemdict /DEVICEWIDTHPOINTS known not and
  1805. systemdict /DEVICEHEIGHTPOINTS known not and
  1806.  {    % Convert the paper size to device dimensions.
  1807.    true statusdict /.pagetypenames get
  1808.     { PAPERSIZE eq
  1809.        { PAPERSIZE load
  1810.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1811.          1 get /DEVICEHEIGHTPOINTS exch def
  1812.          pop false exit
  1813.        }
  1814.       if
  1815.     }
  1816.    forall
  1817.     { (Unknown paper size: ) print PAPERSIZE ==only (.) =
  1818.     }
  1819.    if
  1820.  }
  1821. if
  1822. % Adjust the device parameters per the command line.
  1823. % It is possible to specify resolution, pixel size, and page size;
  1824. % since any two of these determine the third, conflicts are possible.
  1825. % We simply pass them to .setdeviceparams and let it sort things out.
  1826.    mark /HWResolution //null /HWSize //null /PageSize //null .dicttomark
  1827.    .getdeviceparams .dicttomark begin
  1828.    mark
  1829.     % Check for resolution.
  1830.    /DEVICEXRESOLUTION where dup
  1831.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1832.    if
  1833.    /DEVICEYRESOLUTION where dup
  1834.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1835.    if
  1836.    or { /HWResolution HWResolution } if
  1837.     % Check for device sizes specified in pixels.
  1838.    /DEVICEWIDTH where dup
  1839.     { exch pop HWSize 0 DEVICEWIDTH put }
  1840.    if
  1841.    /DEVICEHEIGHT where dup
  1842.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1843.    if
  1844.    or { /HWSize HWSize } if
  1845.     % Check for device sizes specified in points.
  1846.    /DEVICEWIDTHPOINTS where dup
  1847.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1848.    if
  1849.    /DEVICEHEIGHTPOINTS where dup
  1850.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1851.    if
  1852.    or { /PageSize PageSize } if
  1853.     % Check whether any parameters were set.
  1854.    dup mark eq { pop defaultdevice } { defaultdevice putdeviceprops } ifelse
  1855.    end
  1856. %END DEVICE
  1857. % Set any device properties defined on the command line.
  1858. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1859. systemdict /BufferSpace known
  1860. systemdict /MaxBitmap known not and
  1861.  { systemdict /MaxBitmap BufferSpace put
  1862.  } if
  1863. dup getdeviceprops
  1864. counttomark 2 idiv
  1865.  { systemdict 2 index known
  1866.     { pop dup load counttomark 2 roll }
  1867.     { pop pop }
  1868.    ifelse
  1869.  } repeat
  1870. counttomark dup 0 ne
  1871.  { 2 add -1 roll putdeviceprops }
  1872.  { pop pop }
  1873. ifelse
  1874. % If the initial device parameters are invalid, the setdevice may fail.
  1875. % Trap this and produce a reasonable error message.
  1876. { setdevice }        % does an erasepage
  1877. INITDEBUG { exec false } { .internalstopped } ifelse {
  1878.   (**** Unable to open the initial device, quitting.) = flush 1 .quit
  1879. } if
  1880.  
  1881. % If the media size is fixed, update the current page device dictionary.
  1882. FIXEDMEDIA
  1883. dup { pop systemdict /.currentpagedevice known } if
  1884. dup { pop .currentpagedevice exch pop } if
  1885. not { (%END MEDIA) .skipeof } if
  1886. currentpagedevice dup length dict .copydict
  1887. dup /Policies
  1888.     % Stack: <pagedevice> <pagedevice> /Policies
  1889. 1 index /InputAttributes
  1890. 2 copy get dup length dict .copydict
  1891.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1892.     %   /InputAttributes <inputattrs'>
  1893. dup 0 2 copy get dup length dict .copydict
  1894.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1895.     %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1896. dup /PageSize 7 index /PageSize get
  1897. put                % PageSize in 0
  1898. put                % 0 in InputAttributes
  1899. put                % InputAttributes in pagedevice
  1900. % Also change the page size policy so we don't get an error.
  1901.     % Stack: <pagedevice> <pagedevice> /Policies
  1902. 2 copy get dup length dict .copydict
  1903.     % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1904. dup /PageSize 7 put        % PageSize in Policies
  1905. put                % Policies in pagedevice
  1906. .setpagedevice
  1907. %END MEDIA
  1908.  
  1909. % Set up the interpreter context version of -dUSeCIEColor option
  1910. % so that .getuseciecolor has the correct value (see gs_setpd.ps)
  1911. /setpagedevice where {
  1912.   pop systemdict /UseCIEColor known {
  1913.     mark /UseCIEColor UseCIEColor .dicttomark setpagedevice
  1914.   } if
  1915. } if
  1916.  
  1917. %END DISPLAYING
  1918.  
  1919. (END DEVICE) VMDEBUG
  1920.  
  1921. % Establish a default upper limit in the character cache,
  1922. % namely, enough room for a 18-point character at the resolution
  1923. % of the default device, or for a character consuming 1% of the
  1924. % maximum cache size, whichever is larger.
  1925. mark
  1926.     % Compute limit based on character size.
  1927.   18 dup dtransform
  1928.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1929.   exch abs cvi mul        % Y
  1930.     % Compute limit based on allocated space.
  1931.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1932.   .max dup 10 idiv exch
  1933. setcacheparams
  1934. % Conditionally disable the character cache.
  1935. NOCACHE { 0 setcachelimit } if
  1936.  
  1937. (END CONFIG) VMDEBUG
  1938.  
  1939. % Initialize graphics.
  1940.  
  1941. .setdefaultscreen
  1942. initgraphics
  1943.  
  1944. % The interpreter relies on there being at least 2 entries
  1945. % on the graphics stack.  Establish the second one now.
  1946. gsave
  1947.  
  1948. % Define some control sequences as no-ops.
  1949. % This is a hack to get around problems
  1950. % in some common PostScript-generating applications.
  1951. <04> cvn JOBSERVER {
  1952.     { { clear cleardictstack //false 0 .startnewjob } 2 .stop } bind
  1953.   } {
  1954.     { }
  1955.   } ifelse def
  1956. <1b> cvn {             % UEL is <esc>%-12345X and acts the same as ^D
  1957.   currentfile (%-12345X) .peekstring pop (%-12345X) eq <04> cvn load if
  1958. } bind def
  1959. <1b45> cvn { } def        % PJL reset prologue (ESC E)
  1960. <1b451b> cvn <1b> cvn load def    % PJL reset epilogue (ESC E + UEL)
  1961. (\001M) cvn            % TBCP initiator
  1962.  { currentfile /TBCPDecode filter cvx exec
  1963.  } bind def
  1964. /@PJL                % H-P job control
  1965.  {
  1966.    % Windows 2000 driver includes PJL into %%BeginFeature block.
  1967.    % Identify this from the pattern on the stack: countdictstack lucas mark
  1968.    % and fail the feature request.
  1969.  
  1970.    count 3 ge {
  1971.      dup mark eq {
  1972.        2 index countdictstack eq {
  1973.           1 index /lucas where { /lucas get eq } { pop false } ifelse {
  1974.             stop
  1975.          } if
  1976.        } if
  1977.      } if
  1978.    } if
  1979.    currentfile //=string readline pop pop
  1980.  } bind def
  1981.  
  1982. % Install the EPS handler if needed
  1983. systemdict /EPSBoundingBoxInit known { EPSBoundingBoxInit } if
  1984.  
  1985. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1986. .currentglobal true .setglobal
  1987. /SAFETY 2 dict
  1988.   dup /safe false put
  1989.   dup /tempfiles 10 dict readonly put
  1990. readonly def
  1991. .setglobal
  1992.  
  1993. /.locksafe {
  1994.   SAFETY /safe get not {
  1995.     <<
  1996.       /PermitFileReading [
  1997.         currentuserparams /PermitFileReading get aload pop
  1998.         /FONTPATH .systemvar (*) .generate_dir_list_templates
  1999.           % Library files : 
  2000.         /LIBPATH  .systemvar (*) .generate_dir_list_templates       
  2001.           % Resource files on OpenVMS requires a separate template (gs:[dir.*]*)
  2002.           % because the (gs:[dir]*) doesn't cover them.
  2003.         /LIBPATH  .systemvar (*) .file_name_separator (*)
  2004.           concatstrings concatstrings .generate_dir_list_templates
  2005.         .languagelevel 2 ge {
  2006.             % Default resources :
  2007.           [ currentsystemparams /GenericResourceDir get] (*) .generate_dir_list_templates
  2008.             % Default resources (OpenVMS, see comment above.) :
  2009.           [ currentsystemparams /GenericResourceDir get] (*) .file_name_separator (*)
  2010.             concatstrings concatstrings .generate_dir_list_templates
  2011.         } if
  2012.       ]
  2013.       /LockFilePermissions true
  2014.     >> setuserparams
  2015.   }
  2016.   if
  2017.   % setpagedevice has the side effect of clearing the page, but
  2018.   % we will just document that. Using setpagedevice keeps the device
  2019.   % properties and pagedevice .LockSafetyParams in agreement even
  2020.   % after a restore that changes the value to false.
  2021.   currentglobal currentpagedevice gcheck setglobal % use correct VM space
  2022.   << /.LockSafetyParams true >> setpagedevice
  2023.   setglobal
  2024.   //SAFETY /safe //true .forceput % overrides readonly
  2025. } .bind executeonly odef
  2026.  
  2027. /.setsafe
  2028. {
  2029.   SAFETY /safe get not {
  2030.     <<
  2031.       /PermitFileReading [ ]
  2032.       /PermitFileWriting [ ]
  2033.       /PermitFileControl [ ]
  2034.     >> setuserparams
  2035.   }
  2036.   if
  2037.   .locksafe
  2038. } .bind executeonly odef
  2039.  
  2040. /deletefile {
  2041.   dup { deletefile } stopped {
  2042.     pop //deletefile $error /errorname get signalerror
  2043.   } {
  2044.     % deletefile succeeded. Remove from tempfile list if present
  2045.     //SAFETY /tempfiles get exch cvn 2 copy known {
  2046.       .forceundef
  2047.     } {
  2048.       pop pop
  2049.     }
  2050.     ifelse
  2051.   }
  2052.   ifelse
  2053. } .bind executeonly odef
  2054.  
  2055. % If a file is opened with .tempfile with SAFER not (yet) set,
  2056. % the file can be deleted later, even if SAFER is set.
  2057. /.tempfile {
  2058.   .tempfile    % filename file
  2059.   //SAFETY /tempfiles get 2 .argindex true .forceput
  2060. } .bind executeonly odef
  2061.  
  2062. % If we are running in SAFER mode, lock things down
  2063. SAFER { .setsafe } if
  2064.  
  2065. % If we delayed binding, make it possible to do it later.
  2066. /.bindnow {
  2067.   currentuserparams /IdiomRecognition .knownget {
  2068.     1 dict dup /IdiomRecognition //false put setuserparams
  2069.   } if
  2070.   //systemdict begin .bindoperators end
  2071.   % Temporarily disable the typecheck error.
  2072.   errordict /typecheck 2 copy get
  2073.   errordict /typecheck { pop } put    % pop the command
  2074.   0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  2075.   //systemdict /.delaybind {} .forceput    % reclaim the space
  2076.   //systemdict /.bindnow .forceundef    % ditto
  2077.   put
  2078.   //systemdict /.forcecopynew .forceundef    % remove temptation
  2079.   //systemdict /.forcedef .forceundef        % ditto
  2080.   //systemdict /.forceput .forceundef        % ditto
  2081.   //systemdict /.forceundef .forceundef        % ditto
  2082.   currentuserparams /IdiomRecognition known {
  2083.     1 dict dup /IdiomRecognition 4 -1 roll put setuserparams
  2084.   } if
  2085. } .bind odef
  2086.  
  2087. % Turn off array packing, since some PostScript code assumes that
  2088. % procedures are writable.
  2089. false setpacking
  2090.  
  2091. (END INIT) VMDEBUG
  2092.  
  2093. /.currentuserparams where {
  2094.   pop
  2095.     % Remove real user params from psuserparams.
  2096.   mark .currentuserparams counttomark 2 idiv {
  2097.     pop psuserparams exch undef
  2098.   } repeat pop
  2099.     % Update the copy of the user parameters.
  2100.   mark .currentuserparams counttomark 2 idiv {
  2101.     userparams 3 1 roll .forceput    % userparams is read-only
  2102.   } repeat pop
  2103.     % Turn on idiom recognition, if available.
  2104.   currentuserparams /IdiomRecognition known {
  2105.     /IdiomRecognition true .definepsuserparam
  2106.   } if
  2107.   psuserparams readonly pop
  2108.   systemdict /.definepsuserparam undef
  2109.     % Save a copy of userparams for use with save/restore
  2110.     % (and, if implemented, context switching).
  2111.   .currentglobal false .setglobal
  2112.      mark userparams { } forall .dicttomark readonly
  2113.      /userparams exch .forcedef        % systemdict is read-only
  2114.   .setglobal
  2115. } if
  2116. /.currentsystemparams where {
  2117.   pop
  2118.     % Remove real system params from pssystemparams.
  2119.   mark .currentsystemparams counttomark 2 idiv {
  2120.     pop pssystemparams exch .forceundef
  2121.   } repeat pop
  2122. } if
  2123.  
  2124. % Set up AlignToPixels :
  2125.  
  2126. /AlignToPixels where {
  2127.   mark /AlignToPixels 2 index /AlignToPixels get .dicttomark setuserparams
  2128.   /AlignToPixels undef
  2129. } if
  2130.  
  2131. % Set up GridFitTT :
  2132.  
  2133. /GridFitTT where {
  2134.   mark /GridFitTT 2 index /GridFitTT get .dicttomark setuserparams
  2135.   /GridFitTT undef
  2136. } if
  2137.  
  2138. % Establish local VM as the default.
  2139. false /setglobal where { pop setglobal } { .setglobal } ifelse
  2140. $error /.nosetlocal false put
  2141.  
  2142. (END GLOBAL) VMDEBUG
  2143.  
  2144. /.savelocalstate where {
  2145.     % If we might create new contexts, save away copies of all dictionaries
  2146.     % referenced from systemdict that are stored in local VM,
  2147.     % and also save a copy of the initial gstate.
  2148.   pop .savelocalstate
  2149. } {
  2150.     % If we're *not* running in a multi-context system and FAKEFONTS is
  2151.     % defined, add the fake fonts to LocalFontDirectory.
  2152.   .definefakefonts    % current VM is local
  2153. } ifelse
  2154.  
  2155. % Execute scheduled inits :
  2156. //.execute_scheduled_inits exec
  2157. currentdict /.execute_scheduled_inits undef
  2158. currentdict /.delayed_init_queue undef
  2159.  
  2160. % Make global and local FontDirectory read-only.
  2161. FontDirectory readonly pop
  2162. /GlobalFontDirectory where { pop GlobalFontDirectory readonly pop } if
  2163.  
  2164. % Remove systemdict entries for things that have been bound in where used
  2165. % and that shouldn't be accessible by name, and close up systemdict.
  2166. currentdict /filterdict .undef
  2167. currentdict /.cidfonttypes .undef
  2168. currentdict /.colorrenderingtypes .undef
  2169. currentdict /.formtypes .undef
  2170. currentdict /.halftonetypes .undef
  2171. currentdict /.imagetypes .undef
  2172. currentdict /.imagemasktypes .undef
  2173. currentdict /.patterntypes .undef
  2174. currentdict /.shadingtypes .undef
  2175. currentdict /.wheredict .undef
  2176. currentdict /.renderingintentdict .undef
  2177. end
  2178.  
  2179. % Clean up VM, and enable GC.
  2180. /vmreclaim where
  2181.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  2182.  } if
  2183. DELAYBIND not {
  2184.   systemdict /.forcecopynew .undef    % remove temptation
  2185.   systemdict /.forcedef .undef        % ditto
  2186.   systemdict /.forceput .undef        % ditto
  2187.   systemdict /.forceundef .undef    % ditto
  2188. } if
  2189. % Move superexec to internaldict if superexec is defined.
  2190. currentdict /superexec .knownget {
  2191.   1183615869 internaldict /superexec 3 -1 roll put
  2192.   currentdict /superexec .undef
  2193. } if
  2194. WRITESYSTEMDICT not { systemdict readonly pop } if
  2195. (END GC) VMDEBUG
  2196.  
  2197. % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
  2198. % if the 'product' is not (Adobe PostScript Parser). A bug has been
  2199. % submitted to Adobe since this also fails with Acrobat Distiller.
  2200. % As a temporary work around, the following HACK will work for
  2201. % devices without spot color support. Once Ghostscript can
  2202. % support DeviceN and spot color separations this will need to
  2203. % be 'true' in some cases.
  2204. userdict /AGM_preserve_spots false put
  2205.  
  2206. % The interpreter will run the initial procedure (start).
  2207.